Page({
  data: {
    collections: [
      {
        id: '1',
        name: '初级绘本集',
        bookCount: 10,
        description: '适合初学者的简单绘本',
        selected: false
      },
      {
        id: '2',
        name: '中级绘本集',
        bookCount: 15,
        description: '适合有一定基础的学习者',
        selected: false
      },
      {
        id: '3',
        name: '高级绘本集',
        bookCount: 20,
        description: '适合高级学习者的复杂绘本',
        selected: false
      },
      {
        id: '4',
        name: '动物主题绘本集',
        bookCount: 12,
        description: '以动物为主题的绘本集合',
        selected: false
      },
      {
        id: '5',
        name: '日常生活绘本集',
        bookCount: 18,
        description: '关于日常生活的实用绘本',
        selected: false
      }
    ],
    selectedCollections: []
  },

  onLoad: function(options) {
    // 页面加载时的初始化
  },

  // 选择绘本集
  onSelectCollection: function(e) {
    const index = e.currentTarget.dataset.index;
    const collections = this.data.collections;
    const collection = collections[index];
    
    if (collection.selected) {
      // 取消选择
      collection.selected = false;
      const selectedCollections = this.data.selectedCollections.filter(item => item.id !== collection.id);
      this.setData({
        collections: collections,
        selectedCollections: selectedCollections
      });
    } else {
      // 选择
      collection.selected = true;
      const selectedCollections = [...this.data.selectedCollections, collection];
      this.setData({
        collections: collections,
        selectedCollections: selectedCollections
      });
    }
  },

  // 确认选择
  onConfirm: function() {
    // 将选择的绘本集保存到全局数据
    const app = getApp();
    if (!app.globalData) {
      app.globalData = {};
    }
    app.globalData.selectedCollections = this.data.selectedCollections;
    
    wx.navigateBack();
  },

  // 返回上一页
  onBack: function() {
    wx.navigateBack();
  }
}); 